package com.pennphoto.shared;

import java.util.Date;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class RegisFieldVerifier {
	
	public static String isValidName(String first,String last,Date dob,String email,String pass,String start1,String start2, String end1,String end2) {
		String error=null;
		if (first.equals("")) {
			error="The Firstname is a mandatory Field!.Please enter your Firstname in it.";
		}
		if (last.equals("")) {
			error="The Lastname is a mandatory Field!.Please enter your Lastname in it.";
		}
		/*if (dob.equals("")) {
			error="The Date of Birth is a mandatory Field!.";
		}*/
		if (email.equals("")) {
			error="The Email is a mandatory Field!.Please enter your Email in it.";
		}
		
		final Pattern pattern;
		final Matcher matcher;
	 
		final String EMAIL_PATTERN = "^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$";		  
			  pattern = Pattern.compile(EMAIL_PATTERN);
		  /**
		   * Validate hex with regular expression
		   * @param hex hex for validation
		   * @return true valid hex, false invalid hex
		   */
		 
	 
			  matcher = pattern.matcher(email);
		if(matcher.matches()== false){
			
			error="The Email address given by you is not valid.Please give a valid email";
			
		}
		
	 
		if (pass.equals("")) {
			error="The Password is a mandatory Field!.Please enter your password in it.";
		}
	
	    char[]arr = first.toCharArray();
	    int len=0;
	    for(int i=0;i<arr.length;i++)
	    {
	    	char c1=arr[i];
	    	if(Character.isLetter(c1))
	    		len++;
	    		    	
	    }
	    if(len!=arr.length){
	    	error="Your Firstname should only have alphabets in it";
	    }
	    char[]arr1 = last.toCharArray();
	    int len1=0;
	    for(int i=0;i<arr1.length;i++)
	    {
	    	char c1=arr1[i];
	    	if(Character.isLetter(c1))
	    		len1++;
	    		    	
	    }
	    if(len1!=arr1.length){
	    	System.out.println(arr1.length);
	    	error="Your Lastname should only have alphabets in it";
	    }
	    if(!start1.equals("")){
	    char[]arr2 = start1.toCharArray();
	    int len2=0;
	    for(int i=0;i<arr2.length;i++)
	    {
	    	char c2=arr2[i];
	    	if(Character.isLetter(c2))
	    		len2++;
	    		    	
	    }
	    if(len2!=0){
	    	error="Your Start year for Instituition 1 should only have digits in it";
	    }
	    if(arr2.length!=4){
	    	error="Your Start year for Instituition 1 should have 4 digits in it";
	    }
	    }
	    if(!start2.equals("")){
	    char[]arr3 = start2.toCharArray();
	    int len3=0;
	    for(int i=0;i<arr3.length;i++)
	    {
	    	char c3=arr3[i];
	    	if(Character.isLetter(c3))
	    		len3++;
	    		    	
	    }
	    if(len3!=0){
	    	error="Your Start year for Instituition 2 should only have digits in it";
	    }
	    if(arr3.length!=4){
	    	error="Your Start year for Instituition 2 should have 4 digits in it";
	    }
	    }
	    if(!end1.equals("")){
	    char[]arr4 = end1.toCharArray();
	    int len4=0;
	    for(int i=0;i<arr4.length;i++)
	    {
	    	char c4=arr4[i];
	    	if(Character.isLetter(c4))
	    		len4++;
	    		    	
	    }
	    if(len4!=0){
	    	error="Your End year for Instituition 1 should only have digits in it";
	    }
	    if(arr4.length!=4){
	    	error="Your End year for Instituition 1 should have 4 digits in it";
	    }
	    }
	    if(!end2.equals("")){
	    char[]arr5 = end2.toCharArray();
	    int len5=0;
	    for(int i=0;i<arr5.length;i++)
	    {
	    	char c5=arr5[i];
	    	if(Character.isLetter(c5))
	    		len5++;
	    		    	
	    }
	    if(len5!=0){
	    	error="Your End year for Instituition 2 should only have digits in it";
	    }
	    if(arr5.length!=4){
	    	error="Your End year for Instituition 2 should have 4 digits in it";
	    }
	    }
		//return username.length() > 3;
		return error;
	}

}
